<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  
  <meta name="generator" content="Hugo 0.98.0" />

  
  <meta name="description" content="走在通往幸福的路上">
  

  
  <link rel="apple-touch-icon" sizes="180x180" href="https://blog.v5u.win/apple-touch-icon.png">

  
  <link rel="icon" type="image/png" sizes="32x32" href="https://blog.v5u.win/favicon-32x32.png">

  
  <link rel="icon" type="image/png" sizes="16x16" href="https://blog.v5u.win/favicon-16x16.png">

  
  <link rel="manifest" href="https://blog.v5u.win/site.webmanifest">

  
  <link rel="mask-icon" href="https://blog.v5u.win/safari-pinned-tab.svg" color="">

  <meta name="msapplication-TileColor" content="">

  <meta name="theme-color" content="">

  
  <link rel="stylesheet" href="https://blog.v5u.win/css/bootstrap.min.css" />

  
  <title>Go Iris 路由 | 为吾优</title>
  

  <style>
body {
  min-width: 300px;
}

.custom-navbar {
  margin-bottom: 1em;
  height: 60px;
}

.custom-navbar a {
  display: inline-block; 
  padding: 18px 0;
  margin-right: 1em; 
  font-weight: bold; 
}

.custom-navbar a:hover,
.custom-navbar a:focus {
  text-decoration: none; 
}

@media print {
  .custom-navbar {
    display: none;
  }
}

article {
  padding-bottom: 1em;
}

img {
  max-width: 100%;
}


body {
  background-color: #fff;
}



body {
  color: #212529;
}



a {
  color: #007bff;
}



a:hover,
a:focus {
  color: #0056b3;
}



.custom-navbar {
  background-color: #212529;
}



.custom-navbar a {
  color: rgba(255,255,255,.75);
}



.custom-navbar a:hover,
.custom-navbar a:focus {
  color: rgba(255,255,255,1);
}



.container {
  max-width: 800px;
}





</style>
</head>

<body>
  <nav class="custom-navbar">
  <div class="container">
    
    <a href="/">文章</a>
    
    <a href="/tags/">标签</a>
    
    <a href="/about/">关于</a>
    
    <a href="/index.xml">RSS</a>
    
  </div>
</nav>
  
  <div class="container">
    <article>
      <h1>Go Iris 路由</h1>
<h5 id="路由配置规则">路由配置规则</h5>
<p>直接通过 function 绑定 controller，function name 映射到 路由的地址</p>
<p>function named rule：</p>
<pre tabindex="0"><code>func(*Controller) GetLoginBy(id int64)
绑定的controller HTTP-method+routePath
map to - GET:/user/login/{param:long}
</code></pre><p>通过控制器方法的输入参数访问动态路径参数，不需要绑定。当您使用Iris的默认语法来解析来自控制器的处理程序时，您需要使用By字来为方法添加后缀，大写是一个新的子路径。例： 如这种形式 mvc.New(app.Party(&quot;/user&quot;)).Handle(new(user.Controller)) 则:</p>
<ul>
<li>func(*Controller) Get() - GET:/user</li>
<li>func(*Controller) Post() - POST:/user</li>
<li>func(*Controller) GetLogin() - GET:/user/login</li>
<li>func(*Controller) PostLogin() - POST:/user/login</li>
<li>func(*Controller) GetProfileFollowers() - GET:/user/profile/followers</li>
<li>func(*Controller) PostProfileFollowers() - POST:/user/profile/followers</li>
<li>func(*Controller) GetBy(id int64) - GET:/user/{param:long}</li>
<li>func(*Controller) PostBy(id int64) - POST:/user/{param:long}</li>
</ul>

    </article>
  </div>

  
  
  

  
</body>

</html>